Skip to content

Raise a clear error for an empty command line (#1618)#2287

Open
arimu1 wants to merge 2 commits into
common-workflow-language:mainfrom
arimu1:fix/1618-empty-command-clear-error
Open

Raise a clear error for an empty command line (#1618)#2287
arimu1 wants to merge 2 commits into
common-workflow-language:mainfrom
arimu1:fix/1618-empty-command-clear-error

Conversation

@arimu1

@arimu1 arimu1 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Problem

Fixes #1618.

A CommandLineTool with no baseCommand, arguments, or input bindings produces an empty command line. cwltool passed that empty list straight to subprocess.Popen([]), which crashes with a raw, confusing error:

IndexError: list index out of range

…originating deep inside subprocess (executable = args[0]), rather than a clean validation error for the malformed-but-parseable document.

Repro

cwlVersion: v1.2
class: CommandLineTool
inputs: []
outputs: []
$ cwltool missing.cwl --debug
...
IndexError: list index out of range

Fix

Guard the empty-command case in JobBase._execute (cwltool/job.py) right after the command list is constructed, and raise a WorkflowException with an actionable message:

Cannot run a CommandLineTool that produces an empty command line. Specify a
'baseCommand', 'arguments', and/or an input with an 'inputBinding' so there is
a program to execute.

The condition is if not commands:, so it only fires when there is genuinely nothing to execute — i.e. no container runtime wrapper (docker run …) and no command. A container job (where runtime supplies docker run <image>) is unaffected, so relying on an image's default CMD still works. The existing except WorkflowException handler turns this into a clean permanentFail instead of an unhandled traceback.

Tests

Added tests/wf/no-basecommand.cwl fixture and test_empty_command_line_error in tests/test_examples.py, asserting a non-zero exit, the new message in stderr, and no IndexError.

$ python -m pytest tests/test_examples.py::test_empty_command_line_error -q
1 passed

Verified black, flake8, and isort are clean on the changed files, and that a normal tool (tests/echo.cwl) still runs.


This change was produced with the assistance of Claude Code (model: Claude Opus). The diff, root-cause analysis, and test were reviewed by a human before submission.

…ge#1618)

A CommandLineTool with no baseCommand, arguments, or input bindings
produces an empty command list. This was passed straight to
subprocess.Popen([]), which crashed with a raw
"IndexError: list index out of range" deep inside subprocess.

Guard the empty case in JobBase._execute and raise a WorkflowException
with an actionable message instead. The existing handler turns this
into a clean permanentFail rather than an unhandled traceback.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@mr-c mr-c force-pushed the fix/1618-empty-command-clear-error branch from 5d5d68a to 6f0ae64 Compare June 25, 2026 13:36
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.16%. Comparing base (1bf7449) to head (f004621).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2287      +/-   ##
==========================================
- Coverage   85.18%   85.16%   -0.02%     
==========================================
  Files          46       46              
  Lines        8591     8593       +2     
  Branches     2011     2012       +1     
==========================================
  Hits         7318     7318              
- Misses        807      810       +3     
+ Partials      466      465       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mr-c mr-c left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dear @arimu1 ; thank you for using cwltool and your contribution. I am happy to accept trivial contributions made with an LLM, but please know that we cannot accept larger contributions for legal reasons.

@mr-c mr-c enabled auto-merge (rebase) June 25, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CommandLineTool without baseCommand → IndexError

2 participants